package day2;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author oldliu
 * @since 1.0
 */
public class Set1 {
    public static void main(String[] args) {
        Set set=new HashSet();
        set.add("弼马温");
        set.add("孙悟空");
        set.add("孙悟空");
        set.add("美猴王");
        set.add("弼马温");
        set.add("弼马温");
        set.add(55);
        set.add(4.6);
        System.out.println(set.size());
        System.out.println(set);
        //怎么遍历set
        System.out.println("------------增强for-------------");
        for(Object o:set)
            System.out.print(o+"\t");
        System.out.println();
        System.out.println("------------转换成数组-------------");
        Object[] objects = set.toArray();
        System.out.println("-----------迭代器遍历--------------");
        Iterator ir = set.iterator();
        while (ir.hasNext()){
            Object obj=ir.next();
            System.out.print(obj+"\t");
        }
        System.out.println();
    }
}
